package ink.tiptop.utils.ssh;

import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

@Getter
@Setter
public class SshInfo {

    private String host;
    private int port;
    private String username;
    private String password;

    private String identity = "秘钥信息";
    private String passphrase = "";


    public SshInfo(String host, int port, String username, String password) {
        this.host = host;
        this.port = port;
        this.username = username;
        this.password = password;
    }

    public SshInfo(String host, int port, String username, String identity, String passphrase) {
        this.host = host;
        this.port = port;
        this.username = username;
        this.identity = identity;
        this.passphrase = passphrase;
    }

    public SshInfo(String host, int port, String username, String password, String identity, String passphrase) {
        this.host = host;
        this.port = port;
        this.username = username;
        this.password = password;
        this.identity = identity;
        this.passphrase = passphrase;
    }

    // 密码实例
    public static SshInfo passInstance(String host, int port, String user, String pass) {
        return new SshInfo(host, port, user, pass);
    }

    // 公钥实例
    public static SshInfo keyInstance(String host, int port, String user, String key, String phrase) {
        return new SshInfo(host, port, user, key, phrase);
    }

    // 定义host+port+username+password为同一配置对象
    @Override
    public boolean equals(Object o) {
        if (this == o) {

            return true;
        }
        if (o == null || getClass() != o.getClass()) {

            return false;
        }
        SshInfo sshInfo = (SshInfo) o;
        return port == sshInfo.port &&
                Objects.equals(host, sshInfo.host) &&
                Objects.equals(username, sshInfo.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(host, username, port);
    }
}
